package com.spring.arch.operation;


import com.spring.arch.common.sourcegenerator.impl.*;
import com.spring.arch.common.sourcegenerator.utils.Configuration;
import com.spring.arch.common.sourcegenerator.impl.*;
import com.spring.arch.common.sourcegenerator.utils.Configuration;

public class GeneratorStarter {
    protected final String basePackage;
    protected final String[] models;
    protected final String outputMode;
    protected final boolean override;


    public GeneratorStarter(final String basePackage, final String outputMode, final boolean override, final String... models) {
        this.basePackage = basePackage;
        this.outputMode = outputMode;
        this.override = override;
        this.models = models;
    }

    public void generate() throws ClassNotFoundException {
        for (final String modelClass : this.models) {
            final Class<?> modelClazz = Class.forName(this.basePackage + "." + modelClass);
            final Configuration config = new Configuration(modelClazz, this.outputMode, null, this.override);
            final RepositoryGenerator repositoryGenerator = new RepositoryGenerator(config);
            final ServiceGenerator serviceGenerator = new ServiceGenerator(config);
            final DtoGenerator dtoGenerator = new DtoGenerator(config);
            final ConverterGenerator ConverterGenerator = new ConverterGenerator(config);
            final ControllerGenerator controllerGenerator = new ControllerGenerator(config);
            repositoryGenerator.generate();
            serviceGenerator.generate();
            dtoGenerator.generate();
            ConverterGenerator.generate();
            controllerGenerator.generate();
        }
    }

    public static void main(final String[] args) throws ClassNotFoundException {
    	final String basePackage = "com.spring.arch.operation.rental.model";
        final String[] models = {
                "Lessee", "LesseeInvoice", "LesseeContact"
        };
        final String outputMode = "file";
        final boolean override = false;

        final GeneratorStarter starter = new GeneratorStarter(basePackage, outputMode, override, models);
        starter.generate();
    }
}
